"""
@title(TenX腾晓2024年11月考核答题文件)
@warning(请勿修改参数和返回值)
@warning(请认真填写__init__中的数据)
@author(1323230180)
"""


class TenXClass:
    def __init__(self):
        self.name = "参考答案"
        self.id = "参考答案"

    @staticmethod
    def question1(n: int) -> list[str]:
        def change(num):
            text = ""
            while num > 0:
                text = str(num % 4) + text
                num = num // 4
            return text

        return [change(i) for i in range(1, n + 1)]

    @staticmethod
    def question2() -> list[tuple[int, int, int]]:
        num_list = []
        for i in range(20):
            for j in range(34):
                for k in range(34):
                    if i + j + k * 3 == 100 and i * 5 + j * 3 + k == 100:
                        num_list.append((i, j, k * 3))
        return num_list
        # return [
        #     (i, j, k * 3)
        #     for i in range(20)
        #     for j in range(34)
        #     for k in range(34)
        #     if i + j + k * 3 == 100 and i * 5 + j * 3 + k == 100
        # ]

    @staticmethod
    def question3(equipment: list[str], prop: list[str], material: list[str], items: list[str]) -> dict[str, list[str]]:
        sort_dict = {"equipment": [], "prop": [], "material": []}
        for i in items:
            if i in equipment:
                sort_dict["equipment"].append(i)
                continue
            if i in prop:
                sort_dict["prop"].append(i)
                continue
            if i in material:
                sort_dict["material"].append(i)
        return sort_dict
        # sort_dict = {
        #     "equipment": [item for item in items if item in equipment],
        #     "prop": [item for item in items if item in prop],
        #     "material": [item for item in items if item in material]
        # }
        # return sort_dict

    @staticmethod
    def question4_method1(item_values: dict[str, int], items: list[str]) -> tuple[list[str], int]:
        max_value = 0
        item_record = []
        range_generator = range(len(items))
        for i in range_generator:
            for j in range_generator:
                for k in range_generator:
                    temp_value = item_values[items[i]] + item_values[items[j]] + item_values[items[k]]
                    if temp_value > max_value and i != j and j != k and i != k:
                        max_value = temp_value
                        item_record = [items[i], items[j], items[k]]
        return item_record, max_value

    @staticmethod
    def question4_method2(item_values: dict[str, int], items: list[str]) -> tuple[list[str], int]:
        sorted_list = sorted(item_values.items(), key=lambda dic: (dic[1], dic[0]), reverse=True)
        num = 0  # 已选择物品数
        item_record = []
        max_value = 0
        for key, value in sorted_list:
            for item in items:
                if num == 3:
                    break
                if key == item:
                    num += 1
                    item_record.append(item)
                    max_value += value

        return item_record, max_value

    @staticmethod
    def question5(matrix: list[list[int]]) -> list[tuple[int, int]]:
        coordinate_list = []
        for i in range(len(matrix)):
            for j in range(len(matrix[i])):
                if matrix[i][j] == 0:
                    coordinate_list.append((i + 1, j + 1))
        return coordinate_list
        # return [(i + 1, j + 1) for i, row in enumerate(matrix) for j, value in enumerate(row) if value == 0]
